// 文章内容组件

<template>
  <!-- 根据新闻模块不同分成3种；使用v-if判断 -->
  <!-- 点击跳转到相应id的文章详情页 -->
  <div
    class="single"
    v-if="post.type === 1 && post.cover.length < 3"
    @click="$router.push({path:`/articleDetail/${post.id}`})"
  >
    <!-- 左侧文字展示 -->
    <div class="left">
      <p class="content">{{post.title}}</p>
      <p class="info">
        <span>{{post.user.nickname}}</span>
        <span>{{post.comment_length}}跟帖</span>
      </p>
    </div>
    <!-- 右侧图片 -->
    <div class="right">
      <img :src="post.cover[0].url" alt />
    </div>
  </div>
  <div
    class="single2"
    v-else-if="post.type === 2 && post.cover.length < 3"
    @click="$router.push({path:`/articleDetail/${post.id}`})"
  >
    <p class="content">{{post.title}}</p>
    <div class="playarea">
      <img :src="post.cover[0].url" alt />
      <div class="playicon">
        <van-icon name="play" />
      </div>
    </div>
    <p class="info">
      <span>{{post.user.nickname}}</span>
      <span>{{post.comment_length}}跟帖</span>
    </p>
  </div>
  <div
    class="single3"
    v-else-if="post.type === 1 && post.cover.length>=3"
    @click="$router.push({path:`/articleDetail/${post.id}`})"
  >
    <p class="content">{{post.title}}</p>
    <div class="imgs">
      <img :src="item.url" alt v-for="item in post.cover" :key="item.id" />
    </div>
    <p class="info">
      <span>{{post.user.nickname}}</span>
      <span>{{post.comment_length}}跟帖</span>
    </p>
  </div>
</template>

<script>
export default {
  props: {
    post: {
      type: Object, // 父组件传递过来的post只能是对象
      required: true,
    },
  },
};
</script>

<style lang="less" scoped>
body {
  // overflow-x: hidden;
  // overflow-y: hidden;
  background: tan;
}
.single {
  background: #fdfaf6;
  display: flex;
  justify-content: space-between;
  padding: 15 * 100vw/360 0;
  border-bottom: 1 * 100vw/360 solid #ddd;
  .left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 0 10 * 100vw/360;
    .content {
      color: rgb(55, 66, 77);
      overflow: hidden;
      text-overflow: ellipsis;
      /* 弹性伸缩盒子模型显示 */
      display: -webkit-box;
      /* 限制在一个块元素显示的文本的行数 */
      -webkit-line-clamp: 2;
      /* 设置或检索伸缩盒对象的子元素的排列方式 */
      -webkit-box-orient: vertical;
    }
    .info {
      span {
        margin: 0 5 * 100vw/360;
        color: rgb(43, 53, 47);
      }
    }
  }
  .right {
    img {
      width: 120 * 100vw/360;
      height: 70 * 100vw/360;
      object-fit: cover;
      padding: 0 5 * 100vw/360;
    }
  }
  .imgs {
    display: flex;
    padding: 10 * 100vw/360 0 0 0;
    > img {
      flex: 1;
      padding: 0 5 * 100vw/360;
      box-sizing: border-box;
      display: block;
    }
  }
  .video {
    width: 100%;
    height: 170/360 * 100vw;
    padding: 10 * 100vw/360;
    box-sizing: border-box;
    > img {
      width: 100%;
      height: 100%;
    }
  }
}

.single2 {
  background: #fdfaf6;
  border-bottom: 1 * 100vw/360 solid #ccc;
  padding: 8 * 100vw/360 0;
  .playarea {
    width: 100%;
    position: relative;
    margin-bottom: 10 * 100vw/360;
    img {
      width: 100%;
      display: block;
    }
    .playicon {
      width: 60 * 100vw/360;
      height: 60 * 100vw/360;
      border-radius: 50%;
      background-color: rgba(0, 0, 0, 0.4);
      box-shadow: 0 * 100vw/360 0 * 100vw/360 15 * 100vw/360 #fff;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      justify-content: center;
      .van-icon {
        font-size: 40 * 100vw/360;
        color: #fff;
        line-height: 60 * 100vw/360;
      }
    }
  }
}
.single3 {
  background: #fdfaf6;
  width: 100vw;
  .imgs {
    width: 100%;
    display: flex;
    padding: 10 * 100vw/360 0 0 0;
    img {
      width: 120/360 * 100vw;
      height: 70/360 * 100vw;
      // 让图片自动的调整大小，根据父容器的大小自动调整
      object-fit: cover;
      padding-right: 5 * 100vw/360;
    }
  }
}
</style>